package com.yike.user.strategy.login.source;

import com.yike.common.exception.BusinessException;
import com.yike.common.vo.LoginUserInfoVo;
import com.yike.user.entity.User;
import com.yike.user.param.LoginParam;
import com.yike.user.strategy.login.type.AccountLoginStrategy;
import com.yike.user.strategy.login.type.LoginTypeStrategy;
import com.yike.user.strategy.login.type.SmsLoginStrategy;
import com.yike.user.strategy.login.type.WxAppLoginStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Sakura
 * @date 2024/6/17 14:30
 */
@Service
public class LoginSourceContext {

    private final Map<Integer, LoginSourceStrategy> strategyMap = new HashMap<>();

    @Autowired
    private AgentLoginStrategy agentLoginStrategy;

    @Autowired
    private UserLoginStrategy userLoginStrategy;

    @Autowired
    private MerchantLoginStrategy merchantLoginStrategy;

    @PostConstruct
    public void init() {
        strategyMap.put(1, userLoginStrategy);
        strategyMap.put(2, merchantLoginStrategy);
        strategyMap.put(3, agentLoginStrategy);
    }

    public void login(LoginUserInfoVo loginUserInfoVo, Integer loginSource) {
        LoginSourceStrategy strategy = strategyMap.get(loginSource);
        if (strategy != null) {
            strategy.login(loginUserInfoVo);
        } else {
            throw new BusinessException(500, "无效的登录来源: " + loginSource);
        }
    }
}
